package org.iwidget.model.javascript;
import org.iwidget.desktop.model.ElementImage;
import org.iwidget.desktop.model.WidgetElement;
import org.mozilla.javascript.*;
/**
 *
 * @author Muhammad Hakim A
 */


public class ImgElementJS extends ScriptableObject
{

    public String getClassName()
    {
        if(elementData != null)
            return elementData.getName();
        else
            return "Image";
    }

    public ImgElementJS()
    {
        elementData = new ElementImage();
        elementData.setName("Image");
    }

    public ImgElementJS(WidgetElement widget)
    {
        elementData = new ElementImage();
        elementData.setName("Image");
        elementData.widget = widget;
    }

    public ImgElementJS(WidgetElement widget, String name)
    {
        elementData = new ElementImage();
        elementData.setName(name);
        elementData.widget = widget;
        setDefaults();
    }

    public ElementImage getElementData()
    {
        return elementData;
    }

    public void setElementData(ElementImage d)
    {
        elementData = d;
    }

    private void setDefaults()
    {
        try
        {
            defineProperty("alignment", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("cursor", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("height", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("name", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("onKeyDown", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("onKeyUp", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("onMouseUp", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("onMouseDown", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("onMouseEnter", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("onMouseExit", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("opacity", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("owner", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("rotation", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("source", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("tooltip", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("visible", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("width", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("x", org.iwidget.model.javascript.ImgElementJS.class, 0);
            defineProperty("y", org.iwidget.model.javascript.ImgElementJS.class, 0);
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
    }

    public void jsConstructor()
    {
        if(elementData.widget == null)
        {
            Scriptable scope = ScriptableObject.getTopLevelScope(this);
            Object obj = scope.get("widget", scope);
            elementData.widget = (WidgetElement)Context.toType(obj, org.iwidget.desktop.model.WidgetElement.class);
        }
        setDefaults();
        elementData.widget.uiObjects.add(elementData);
        if(elementData.widget.getUIComponent() != null)
            elementData.widget.getUIComponent().insertImageJS(elementData);
    }

    public String getAlignment()
    {
        return elementData.getAlignment();
    }

    public void setAlignment(String s)
    {
        elementData.setAlignment(s);
    }

    public String getCursor()
    {
        return elementData.getCursor();
    }

    public void setCursor(String string)
    {
        elementData.setCursor(string);
    }

    public int getHeight()
    {
        return elementData.getHeight();
    }

    public void setHeight(int i)
    {
        elementData.setHeight(i);
    }

    public String getName()
    {
        return elementData.getName();
    }

    public void setName(String s)
    {
        elementData.setName(s);
    }

    public int getOpacity()
    {
        return elementData.getOpacity();
    }

    public void setOpacity(int i)
    {
        elementData.setOpacity(i);
    }

    public Object getOwner()
    {
        return elementData.getOwner();
    }

    public void setOwner(Object o)
    {
        elementData.setOwner(o);
    }

    public double getRotation()
    {
        return elementData.getRotation();
    }

    public void setRotation(double d)
    {
        elementData.setRotation(d);
    }

    public String getSource()
    {
        return elementData.getSource();
    }

    public void setSource(String string)
    {
        elementData.setSource(string);
    }

    public String getTooltip()
    {
        return elementData.getTooltip();
    }

    public void setTooltip(String s)
    {
        elementData.setTooltip(s);
    }

    public boolean getVisible()
    {
        return elementData.getVisible();
    }

    public void setVisible(boolean b)
    {
        elementData.setVisible(b);
    }

    public int getWidth()
    {
        return elementData.getWidth();
    }

    public void setWidth(int i)
    {
        elementData.setWidth(i);
    }

    public int getX()
    {
        return elementData.getX();
    }

    public void setX(int i)
    {
        elementData.setX(i);
    }

    public int getY()
    {
        return elementData.getY();
    }

    public void setY(int i)
    {
        elementData.setY(i);
    }

    public void setOnMouseUp(String string)
    {
        elementData.setAction("onMouseUp", string);
    }

    public String getOnMouseUp()
    {
        return null;
    }

    public void setOnMouseDown(String string)
    {
        elementData.setAction("onMouseDown", string);
    }

    public String getOnMouseDown()
    {
        return null;
    }

    public void setOnMouseEnter(String string)
    {
        elementData.setAction("onMouseExit", string);
    }

    public String getOnMouseEnter()
    {
        return null;
    }

    public void setOnMouseExit(String string)
    {
        elementData.setAction("onMouseEnter", string);
    }

    public String getOnMouseExit()
    {
        return null;
    }

    public void setOnKeyDown(String string)
    {
        elementData.setAction("onKeyDown", string);
    }

    public String getOnKeyDown()
    {
        return null;
    }

    public void setOnKeyUp(String string)
    {
        elementData.setAction("onKeyUp", string);
    }

    public String getOnKeyUp()
    {
        return null;
    }

    public void setOnKeyPress(String string)
    {
        elementData.setAction("onKeyPress", string);
    }

    public String getOnKeyPress()
    {
        return null;
    }

    public void jsFunction_fade(int startOpacity, int endOpacity)
    {
        elementData.fade(startOpacity, endOpacity, 20);
    }

    public void jsFunction_fade(int startOpacity, int endOpacity, int speed)
    {
        elementData.fade(startOpacity, endOpacity, speed);
    }

    public void jsFunction_moveTo(int newX, int newY, int speed)
    {
        elementData.moveTo(newX, newY, speed);
    }

    public void jsFunction_slideShow()
    {
        elementData.slideShow();
    }

    public void jsFunction_slideHide(String dir, int conceal, int speed)
    {
        elementData.slideHide(dir, conceal, speed);
    }

    private static final long serialVersionUID = 0x3634393936343736L;
    ElementImage elementData;
}